import {createRouter, createWebHistory, type RouteRecordRaw} from "vue-router";

// 作为导航栏使用的路由配置
export const navigation: RouteRecordRaw[] = [
    {
        name: "首页",
        path: "/forum",
        children: [
            {path: "favor", name: "收藏版面", component: () => import("./index/FavorForum.vue")},
            {path: "search", name: "搜索版面", component: () => import("./index/ForumSearch.vue")},
            {path: "groups", name: "论坛版面", component: () => import("./index/IndexForum.vue")},
        ]
    },
    {
        name: "配置",
        path: "/config",
        children: [
            {path: "account", name: "账号管理", component: () => import("./config/Account.vue")},
            {path: "ui", name: "界面", component: () => import("./Blank.vue")},
            {path: "emote", name: "表情", component: () => import("./config/Emote.vue")},
            {path: "blackList", name: "黑名单", component: () => import("./config/BlockList.vue")},
        ]
    },
]

export enum TopicListRoute {
    FORUM_LIST = "版面浏览",
    FORUM_SEARCH = "版面搜索",
    FORUM_RECOMMEND = "版面精华",
    COL_LIST = "合集浏览",
    COL_SEARCH = "合集搜索",
    USER_TOPIC = "用户发布的主题",
    USER_REPLIES = "用户发布的回复",
}

export enum PriMsgRoute {
    LIST = "私信列表",
    READ = "私信阅读",
}


export enum ReplyListRoute {
    LIST = "回复列表",
    SINGLE = "单个回复",
    ANONYMOUS = "只读匿名",
}

export enum UserRoute {
    USER_CENTER_ID = "用户中心-ID",
    USER_CENTER_USERNAME = "用户中心-用户名",
    USER_FAVOR = "用户收藏",
    USER_ITEMS = "用户道具",
}

export const PostRouteName = "发帖";

const router = createRouter({
    history: createWebHistory(),
    routes: [
        // 首页重定向到收藏版面
        {
            path: '/',
            redirect: '/forum/favor'
        },
        // 主题列表：版面、搜索、精华区
        {
            name: "版面",
            path: '/forum',
            children: [
                {
                    name: TopicListRoute.FORUM_LIST,
                    path: ":fid(-*\\d+)",
                    component: () => import("./topics/TopicList.vue"),
                },
                {
                    name: TopicListRoute.FORUM_SEARCH,
                    path: ":keyword/:fid/search",
                    component: () => import("./topics/TopicList.vue"),
                },
                {
                    name: TopicListRoute.FORUM_RECOMMEND,
                    path: "recommend/:fid(-*\\d+)",
                    component: () => import("./topics/TopicList.vue"),
                },
            ]
        },
        // 主题列表： 合集，搜索
        {
            name: "合集",
            path: '/col',
            children: [
                {
                    name: TopicListRoute.COL_LIST,
                    path: ":stid(-*\\d+)",
                    component: () => import("./topics/TopicList.vue"),
                },
                {
                    name: TopicListRoute.COL_SEARCH,
                    path: ":keyword/:stid/search",
                    component: () => import("./topics/TopicList.vue"),
                },
            ]
        },
        // 回复列表： 常规，只看匿名，单个回复
        {
            name: '回复',
            path: '/topic',
            children: [
                {
                    name: ReplyListRoute.LIST,
                    path: ":tid(\\d+)",
                    component: () => import("./topics/TopicRead.vue"),
                },
                {
                    name: ReplyListRoute.ANONYMOUS,
                    path: ":tid(\\d+)/:pid(\\d+)",
                    component: () => import("./topics/TopicRead.vue"),
                },
                {
                    name: ReplyListRoute.SINGLE,
                    path: "reply/:pid(\\d+)",
                    component: () => import("./topics/TopicRead.vue"),
                },
            ]
        },
        // 发帖
        {
            name: PostRouteName,
            path: "/post/:action(new|modify|reply|quote)",
            component: () => import("./post/Post.vue"),
        },
        // 用户： 用户中心，用户发布的主题，用户发布的回复
        {
            name: '用户',
            path: "/user",
            children: [
                {
                    name: UserRoute.USER_CENTER_ID,
                    path: ":userId(\\d+)",
                    component: () => import("./user/User.vue"),
                },
                {
                    name: UserRoute.USER_CENTER_USERNAME,
                    path: ":username",
                    component: () => import("./user/User.vue"),
                },
                {
                    name: UserRoute.USER_FAVOR,
                    path: "favor/:userId(\\d+)",
                    component: () => import("./user/UserFavor.vue"),
                },
                {
                    name: TopicListRoute.USER_TOPIC,
                    path: ":userId(\\d+)/topic",
                    component: () => import("./topics/TopicList.vue"),
                },
                {
                    name: TopicListRoute.USER_REPLIES,
                    path: ":userId(\\d+)/replies",
                    component: () => import("./topics/TopicList.vue"),
                },
                {
                    name: UserRoute.USER_ITEMS,
                    path: "items",
                    component: () => import("./user/UserItems.vue"),
                },


            ]
        },
        // 私信
        {
            path: "/pri-msg",
            children: [
                {path: "list", name: PriMsgRoute.LIST, component: () => import("./message/PrivateMessageList.vue")},
                {path: ":mid(\\d+)", name: PriMsgRoute.READ, component: () => import("./message/PrivateMessageRead.vue")},
            ]
        },
        ...navigation
    ]
})

export default router
